print "begins combing for the df and cf related info."
print "the approach is different from combing the tf related info."

outputFileName = "/data5/team/weijiang/the_new_trip_of_feature_generation/assignment/results/final-complexFeaturesSupportedFileProductionForDf_dicts.txt"
outputFileHandler = open(outputFileName,"w")
outputFileHandler.write("queryVarianceID queryVarianceContent df_M_1 df_M_4 df_M_8 df_M_32 df_N_ordered_1 df_N_ordered_4 df_N_ordered_8 df_N_ordered_32 df_N_unordered_1 df_N_unordered_4 df_N_unordered_8 df_N_unordered_32" + "\n")


#init
Df_dicts = {}
for i in range(0,665):
    # print i
    currentDfDict = {}
    currentDfDict["variantContent"] = ""
    currentDfDict["M_1"] = 0
    currentDfDict["M_4"] = 0
    currentDfDict["M_8"] = 0
    currentDfDict["M_32"] = 0
    
    currentDfDict["N_ordered_1"] = 0
    currentDfDict["N_ordered_4"] = 0
    currentDfDict["N_ordered_8"] = 0
    currentDfDict["N_ordered_32"] = 0
    
    currentDfDict["N_unordered_1"] = 0
    currentDfDict["N_unordered_4"] = 0
    currentDfDict["N_unordered_8"] = 0
    currentDfDict["N_unordered_32"] = 0
    
    Df_dicts[i] = currentDfDict

# assign 
for i in range(0,3):
    print i
    inputFileName = "/data5/team/weijiang/the_new_trip_of_feature_generation/assignment/results/final-complexFeaturesSupportedFileProductionForDf_dicts.txt_part_" + "%2d" % i
    inputFileHandler = open(inputFileName,"r")
    inputFileHandler.readline()
    for line in inputFileHandler.readlines():
        lineElements = line.split(" ")
        variantID = int(lineElements[0])
        
        Df_dicts[variantID]["variantContent"] = lineElements[1].strip()
        Df_dicts[variantID]["M_1"] += int(lineElements[2])
        Df_dicts[variantID]["M_4"] += int(lineElements[3])
        Df_dicts[variantID]["M_8"] += int(lineElements[4])
        Df_dicts[variantID]["M_32"] += int(lineElements[5])

        Df_dicts[variantID]["N_ordered_1"] += int(lineElements[6])
        Df_dicts[variantID]["N_ordered_4"] += int(lineElements[7])
        Df_dicts[variantID]["N_ordered_8"] += int(lineElements[8])
        Df_dicts[variantID]["N_ordered_32"] += int(lineElements[9])
        
        Df_dicts[variantID]["N_unordered_1"] += int(lineElements[10])
        Df_dicts[variantID]["N_unordered_4"] += int(lineElements[11])
        Df_dicts[variantID]["N_unordered_8"] += int(lineElements[12])
        Df_dicts[variantID]["N_unordered_32"] += int(lineElements[13])    
    inputFileHandler.close()


#output
for variantID in Df_dicts:
    outputFileHandler.write(str(variantID) + " " + Df_dicts[variantID]["variantContent"] + " " + str(Df_dicts[variantID]["M_1"]) + " " + str(Df_dicts[variantID]["M_4"]) +" "+ str(Df_dicts[variantID]["M_8"]) +" "+ str(Df_dicts[variantID]["M_32"]) + " " + str(Df_dicts[variantID]["N_ordered_1"]) + " " + str(Df_dicts[variantID]["N_ordered_4"]) + " " + str(Df_dicts[variantID]["N_ordered_8"]) + " " + str(Df_dicts[variantID]["N_ordered_32"]) + " " + str(Df_dicts[variantID]["N_unordered_1"]) + " " + str(Df_dicts[variantID]["N_unordered_4"]) + " " + str(Df_dicts[variantID]["N_unordered_8"]) + " " + str(Df_dicts[variantID]["N_unordered_32"]) + "\n")
outputFileHandler.close()

    
print "ends."


'''
print "begins combing for the df and cf related info."
print "the approach is different from combing the tf related info."

outputFileName = "/data5/team/weijiang/the_new_trip_of_feature_generation/assignment/results/final-complexFeaturesSupportedFileProductionForCf_dicts.txt"
outputFileHandler = open(outputFileName,"w")
outputFileHandler.write("queryVarianceID queryVarianceContent cf_M_1 cf_M_4 cf_M_8 cf_M_32 cf_N_ordered_1 cf_N_ordered_4 cf_N_ordered_8 cf_N_ordered_32 cf_N_unordered_1 cf_N_unordered_4 cf_N_unordered_8 cf_N_unordered_32" + "\n")


#init
Cf_dicts = {}
for i in range(0,665):
    # print i
    currentCfDict = {}
    currentCfDict["variantContent"] = ""
    currentCfDict["M_1"] = 0
    currentCfDict["M_4"] = 0
    currentCfDict["M_8"] = 0
    currentCfDict["M_32"] = 0
    
    currentCfDict["N_ordered_1"] = 0
    currentCfDict["N_ordered_4"] = 0
    currentCfDict["N_ordered_8"] = 0
    currentCfDict["N_ordered_32"] = 0
    
    currentCfDict["N_unordered_1"] = 0
    currentCfDict["N_unordered_4"] = 0
    currentCfDict["N_unordered_8"] = 0
    currentCfDict["N_unordered_32"] = 0
    
    Cf_dicts[i] = currentCfDict

# assign 
for i in range(0,20):
    print i
    inputFileName = "/data5/team/weijiang/the_new_trip_of_feature_generation/assignment/results/final-complexFeaturesSupportedFileProductionForCf_dicts.txt_part_" + "%2d" % i
    inputFileHandler = open(inputFileName,"r")
    inputFileHandler.readline()
    for line in inputFileHandler.readlines():
        lineElements = line.split(" ")
        variantID = int(lineElements[0])
        
        Cf_dicts[variantID]["variantContent"] = lineElements[1].strip()
        Cf_dicts[variantID]["M_1"] += int(lineElements[2])
        Cf_dicts[variantID]["M_4"] += int(lineElements[3])
        Cf_dicts[variantID]["M_8"] += int(lineElements[4])
        Cf_dicts[variantID]["M_32"] += int(lineElements[5])

        Cf_dicts[variantID]["N_ordered_1"] += int(lineElements[6])
        Cf_dicts[variantID]["N_ordered_4"] += int(lineElements[7])
        Cf_dicts[variantID]["N_ordered_8"] += int(lineElements[8])
        Cf_dicts[variantID]["N_ordered_32"] += int(lineElements[9])
        
        Cf_dicts[variantID]["N_unordered_1"] += int(lineElements[10])
        Cf_dicts[variantID]["N_unordered_4"] += int(lineElements[11])
        Cf_dicts[variantID]["N_unordered_8"] += int(lineElements[12])
        Cf_dicts[variantID]["N_unordered_32"] += int(lineElements[13])    
    inputFileHandler.close()


#output
for variantID in Cf_dicts:
    outputFileHandler.write(str(variantID) + " " + Cf_dicts[variantID]["variantContent"] + " " + str(Cf_dicts[variantID]["M_1"]) + " " + str(Cf_dicts[variantID]["M_4"]) +" "+ str(Cf_dicts[variantID]["M_8"]) +" "+ str(Cf_dicts[variantID]["M_32"]) + " " + str(Cf_dicts[variantID]["N_ordered_1"]) + " " + str(Cf_dicts[variantID]["N_ordered_4"]) + " " + str(Cf_dicts[variantID]["N_ordered_8"]) + " " + str(Cf_dicts[variantID]["N_ordered_32"]) + " " + str(Cf_dicts[variantID]["N_unordered_1"]) + " " + str(Cf_dicts[variantID]["N_unordered_4"]) + " " + str(Cf_dicts[variantID]["N_unordered_8"]) + " " + str(Cf_dicts[variantID]["N_unordered_32"]) + "\n")
outputFileHandler.close()

    
print "ends."
'''
    